<?php


namespace app\api\model;


use think\Model;

class Sale extends Model
{
    use PaginatePassPage;

    protected $table = 'jxc_sale';
    protected $type = ['images' => 'json'];

     // 定义全局的查询范围
     protected function base($query)
     {
         $c = \app\admin\model\Admin::find(\app\http\GetUid::getUId());
         // 门店负责人可查看自己门店的所有信息
         if ($c->level == 2) {
             $maker = \app\admin\model\Admin::where('store', $c->store)->where('level', 3)->column('id');
         } elseif ($c->level == 1) {
             $maker = \app\admin\model\Admin::column('id');
         } else {
             $maker = $c->id;
         }
         $query->whereIn('maker', $maker);
     }

    public function setAccount()
    {
        return $this->belongsTo(SetAccount::class, 'set_account');
    }

    public function relations()
    {
        return $this->hasMany(SaleRelation::class, 'pid');
    }
}
